package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.entity.LimitConfirmItemDO;
import com.cmc.cloud.cmclink.doc.service.LimitConfirmItemService;
import com.cmc.cloud.cmclink.doc.vo.limitconfirmitemvo.LimitConfirmItemCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.limitconfirmitemvo.LimitConfirmItemPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.limitconfirmitemvo.LimitConfirmItemRespVO;
import com.cmc.cloud.cmclink.doc.vo.limitconfirmitemvo.LimitConfirmItemUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * {table.classComment}前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 信息确认类明细")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL + "/confirmItem")
@Validated
public class LimitConfirmItemController {

    @Resource
    private LimitConfirmItemService limitConfirmItemService;

    @Operation(summary = "创建信息确认类明细")
    @PostMapping("/create")
    public CommonResult<Void> createLimitConfirmItem(@Valid @RequestBody LimitConfirmItemCreateReqVO createReqVO) {
        limitConfirmItemService.createLimitConfirmItem(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新信息确认类明细")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission('doc:maintainBCRDCR:userInfoConfirm:edit')")
    public CommonResult<Void> updateLimitConfirmItem(@Valid @RequestBody LimitConfirmItemUpdateReqVO updateReqVO) {
        limitConfirmItemService.updateLimitConfirmItem(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除信息确认类明细")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:maintainBCRDCR:userInfoConfirm:delete')")
    public CommonResult<Void> deleteLimitConfirmItem(@PathVariable("id") Long id) {
        limitConfirmItemService.deleteLimitConfirmItem(id);
        return CommonResult.success();
    }

    @Operation(summary = "通过主id获得信息确认类明细")
    @Parameter(name = "mainId", description = "编号", required = true, example = "1024")
    @GetMapping("getByMainId/{mainId}")
    @UseResponsePropertyAdvice
    public CommonResult<List<LimitConfirmItemRespVO>> getByMainId(@PathVariable("mainId") Long mainId) {
        List<LimitConfirmItemDO> limitConfirmItemDos = limitConfirmItemService.getLimitConfirmItemByMainId(mainId);
        return CommonResult.success(BeanUtil.copyToList(limitConfirmItemDos, LimitConfirmItemRespVO.class));
    }

    @Operation(summary = "获得信息确认类明细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("getById/{id}")
    public CommonResult<LimitConfirmItemRespVO> getLimitConfirmItem(@PathVariable("id") Long id) {
        LimitConfirmItemDO limitConfirmItem = limitConfirmItemService.getLimitConfirmItem(id);
        return CommonResult.success(BeanUtil.copyProperties(limitConfirmItem, LimitConfirmItemRespVO.class));
    }

    @Operation(summary = "获得信息确认类明细列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<LimitConfirmItemRespVO>> getLimitConfirmItemList(@RequestParam("ids") Collection<Long> ids) {
        List<LimitConfirmItemDO> list = limitConfirmItemService.getLimitConfirmItemList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, LimitConfirmItemRespVO.class));
    }

    @Operation(summary = "获得信息确认类明细分页")
    @UseResponsePropertyAdvice
    @PostMapping("/getPage")
    public CommonResult<PageResult<LimitConfirmItemRespVO>> getLimitConfirmItemPage(@Valid @RequestBody LimitConfirmItemPageReqVO pageVO) {
        PageResult<LimitConfirmItemDO> pageResult = limitConfirmItemService.getLimitConfirmItemPage(pageVO);
        List<LimitConfirmItemRespVO> results = BeanUtil.copyToList(pageResult.getList(), LimitConfirmItemRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
